package com.yuezhu.util;

import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.yuezhu.global.ApplicationContext;
import com.yuezhu.R;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * 
 * 全局Toast
 * 
 * @since 1.0
 * @author zhaoshuzhen
 */
public class MyToast {
	private static Toast toast = null;
	private static Toast cToast = null;
	private Field field;
	private Object obj;
	private Method showMethod,hideMethod;
private  static  MyToast myToast ;
	public static  MyToast getInstance(){
		if (myToast == null){
			myToast = new MyToast();
		}
		return  myToast ;
	}
	/**
	 * 
	 * 显示toast
	 * 
	 * @since 1.0
	 * @author liaoww
	 * @param text
	 * @param time
	 */
	public static void showToast(String text, int time) {
		if (toast == null) {
			toast = Toast.makeText(ApplicationContext.getInstance(), text, time);
		}
		if(text!=null){
			toast.setText(text);
			toast.show();
		}
	}
	public static void showDefaltToast(String text) {
		if (toast == null) {
			toast = Toast.makeText(ApplicationContext.getInstance(), text, Toast.LENGTH_SHORT);
		}
		if(text!=null){
			toast.setText(text);
			toast.show();
		}
	}
	public static void customToast(int drawable){
		LayoutInflater inflater = ActUtils.getLayoutInflater();
		View layout = inflater.inflate(R.layout.v_toast, null);
		ImageView image = (ImageView) layout.findViewById(R.id.toast_bg);
		TextView textView = (TextView) layout.findViewById(R.id.toast_tv);
		textView.setVisibility(View.GONE);
		image.setImageResource(drawable);
		cToast = new Toast(ApplicationContext.getInstance());
//		cToast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, 125);
		cToast.setGravity(Gravity.CENTER,0,0);
		cToast.setDuration(Toast.LENGTH_LONG);
		cToast.setView(layout);
		cToast.show();
	}
}
